from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-05-19 14:02:32.719013
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 19, May, 2022
Time: 14:02:39
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.3393
Nobs: 661.000 HQIC: -49.7140
Log likelihood: 8157.58 FPE: 2.02542e-22
AIC: -49.9511 Det(Omega_mle): 1.76940e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.312747 0.060533 5.167 0.000
L1.Burgenland 0.107250 0.038821 2.763 0.006
L1.Kärnten -0.109358 0.020371 -5.368 0.000
L1.Niederösterreich 0.202853 0.080817 2.510 0.012
L1.Oberösterreich 0.122080 0.080007 1.526 0.127
L1.Salzburg 0.256742 0.041275 6.220 0.000
L1.Steiermark 0.042572 0.054108 0.787 0.431
L1.Tirol 0.101176 0.043619 2.320 0.020
L1.Vorarlberg -0.063400 0.038663 -1.640 0.101
L1.Wien 0.032452 0.070720 0.459 0.646
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.044848 0.129030 0.348 0.728
L1.Burgenland -0.031048 0.082749 -0.375 0.708
L1.Kärnten 0.040728 0.043421 0.938 0.348
L1.Niederösterreich -0.181634 0.172267 -1.054 0.292
L1.Oberösterreich 0.448805 0.170541 2.632 0.008
L1.Salzburg 0.284575 0.087981 3.235 0.001
L1.Steiermark 0.106878 0.115335 0.927 0.354
L1.Tirol 0.310977 0.092977 3.345 0.001
L1.Vorarlberg 0.021826 0.082413 0.265 0.791
L1.Wien -0.038060 0.150744 -0.252 0.801
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.183270 0.031084 5.896 0.000
L1.Burgenland 0.090494 0.019935 4.540 0.000
L1.Kärnten -0.007547 0.010460 -0.722 0.471
L1.Niederösterreich 0.257731 0.041500 6.210 0.000
L1.Oberösterreich 0.155504 0.041084 3.785 0.000
L1.Salzburg 0.042168 0.021195 1.990 0.047
L1.Steiermark 0.023705 0.027785 0.853 0.394
L1.Tirol 0.083936 0.022398 3.747 0.000
L1.Vorarlberg 0.053590 0.019854 2.699 0.007
L1.Wien 0.118161 0.036315 3.254 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.110028 0.031133 3.534 0.000
L1.Burgenland 0.046121 0.019966 2.310 0.021
L1.Kärnten -0.014073 0.010477 -1.343 0.179
L1.Niederösterreich 0.185110 0.041566 4.453 0.000
L1.Oberösterreich 0.327204 0.041149 7.952 0.000
L1.Salzburg 0.101690 0.021229 4.790 0.000
L1.Steiermark 0.108875 0.027829 3.912 0.000
L1.Tirol 0.096392 0.022434 4.297 0.000
L1.Vorarlberg 0.059645 0.019885 2.999 0.003
L1.Wien -0.021930 0.036372 -0.603 0.547
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.111061 0.057945 1.917 0.055
L1.Burgenland -0.042828 0.037161 -1.153 0.249
L1.Kärnten -0.046114 0.019500 -2.365 0.018
L1.Niederösterreich 0.143248 0.077361 1.852 0.064
L1.Oberösterreich 0.161266 0.076586 2.106 0.035
L1.Salzburg 0.281528 0.039510 7.125 0.000
L1.Steiermark 0.056035 0.051795 1.082 0.279
L1.Tirol 0.164582 0.041754 3.942 0.000
L1.Vorarlberg 0.095811 0.037010 2.589 0.010
L1.Wien 0.077462 0.067696 1.144 0.253
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.061094 0.045712 1.336 0.181
L1.Burgenland 0.031836 0.029316 1.086 0.277
L1.Kärnten 0.051361 0.015383 3.339 0.001
L1.Niederösterreich 0.208251 0.061030 3.412 0.001
L1.Oberösterreich 0.317232 0.060419 5.251 0.000
L1.Salzburg 0.041306 0.031170 1.325 0.185
L1.Steiermark 0.006346 0.040861 0.155 0.877
L1.Tirol 0.131728 0.032939 3.999 0.000
L1.Vorarlberg 0.065571 0.029197 2.246 0.025
L1.Wien 0.086122 0.053405 1.613 0.107
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.170479 0.054866 3.107 0.002
L1.Burgenland 0.005754 0.035186 0.164 0.870
L1.Kärnten -0.065034 0.018463 -3.522 0.000
L1.Niederösterreich -0.095907 0.073251 -1.309 0.190
L1.Oberösterreich 0.204512 0.072517 2.820 0.005
L1.Salzburg 0.053585 0.037411 1.432 0.152
L1.Steiermark 0.241903 0.049043 4.932 0.000
L1.Tirol 0.500183 0.039535 12.652 0.000
L1.Vorarlberg 0.058632 0.035044 1.673 0.094
L1.Wien -0.071710 0.064099 -1.119 0.263
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.150101 0.060803 2.469 0.014
L1.Burgenland 0.004022 0.038994 0.103 0.918
L1.Kärnten 0.060178 0.020461 2.941 0.003
L1.Niederösterreich 0.180228 0.081177 2.220 0.026
L1.Oberösterreich -0.055750 0.080364 -0.694 0.488
L1.Salzburg 0.206099 0.041459 4.971 0.000
L1.Steiermark 0.133859 0.054349 2.463 0.014
L1.Tirol 0.069547 0.043813 1.587 0.112
L1.Vorarlberg 0.143648 0.038835 3.699 0.000
L1.Wien 0.109935 0.071035 1.548 0.122
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.373759 0.035890 10.414 0.000
L1.Burgenland -0.000165 0.023017 -0.007 0.994
L1.Kärnten -0.021600 0.012078 -1.788 0.074
L1.Niederösterreich 0.216781 0.047916 4.524 0.000
L1.Oberösterreich 0.228274 0.047436 4.812 0.000
L1.Salzburg 0.038764 0.024472 1.584 0.113
L1.Steiermark -0.015846 0.032081 -0.494 0.621
L1.Tirol 0.093154 0.025861 3.602 0.000
L1.Vorarlberg 0.054129 0.022923 2.361 0.018
L1.Wien 0.034523 0.041929 0.823 0.410
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.037349 0.118993 0.174123 0.143778 0.100031 0.086475 0.039182 0.212008
Kärnten 0.037349 1.000000 -0.018788 0.135048 0.052704 0.090153 0.440600 -0.060494 0.094041
Niederösterreich 0.118993 -0.018788 1.000000 0.324119 0.130186 0.283629 0.076050 0.161413 0.300021
Oberösterreich 0.174123 0.135048 0.324119 1.000000 0.220429 0.308821 0.167773 0.150521 0.251726
Salzburg 0.143778 0.052704 0.130186 0.220429 1.000000 0.129525 0.099291 0.114819 0.130723
Steiermark 0.100031 0.090153 0.283629 0.308821 0.129525 1.000000 0.137985 0.118249 0.050787
Tirol 0.086475 0.440600 0.076050 0.167773 0.099291 0.137985 1.000000 0.069282 0.147880
Vorarlberg 0.039182 -0.060494 0.161413 0.150521 0.114819 0.118249 0.069282 1.000000 0.007432
Wien 0.212008 0.094041 0.300021 0.251726 0.130723 0.050787 0.147880 0.007432 1.000000